import React from "react";
import {
  View,
  Text,
  TouchableHighlight,
  NativeModules,
  Platform,
} from "react-native";
import SplashScreen from "react-native-splash-screen";

import { keyRenderContentByTag } from "utils";
import { RNReload } from "components/Reload"; // 安卓

import * as vars from "../../theme";

import styles from "./styles";

const { iOSModule } = NativeModules; // 原生 iOS 模组

class index extends React.Component {
  static navigationOptions = {
    header: null,
    title: "No Header",
  };

  componentDidMount() {
    setTimeout(() => {
      // dispatch({ type: "modal/changeVisible", payload: true }); // 打开全局通知
      SplashScreen.hide();
    }, 3000);
  }

  localOnClickItem = type => {
    const { navigation } = this.props;
    navigation.navigate(type);
  };

  render() {
    const str = `[link target=“_blank” url=“https://www.baidu.com/”]链接跳转测试[/link]↵<br/>以上答案是否解决了您的问题？[link submit="faqvote:001573784842695000950050569b7c29 1 MS7BtL3TzPjXqrLiytQ= wbS908z416qy4srU W2xpbmsgdGFyZ2V0PaGwX2JsYW5robEgdXJsPaGwaHR0cHM6Ly93d3cuYmFpZHUuY29tL6GxXcG0vdPM+NeqsuLK1FsvbGlua10="]解决[/link] [link submit="faqvote:001573784842695000950050569b7c29 2 MS7BtL3TzPjXqrLiytQ= wbS908z416qy4srU W2xpbmsgdGFyZ2V0PaGwX2JsYW5robEgdXJsPaGwaHR0cHM6Ly93d3cuYmFpZHUuY29tL6GxXcG0vdPM+NeqsuLK1FsvbGlua10="]未解决[/link]
    `;
    const res = keyRenderContentByTag(str);
    console.log(res);
    return (
      <View style={styles.root}>
        <TouchableHighlight
          style={styles.item}
          onPress={this.localOnClickItem.bind(this, "Demo1")}
          underlayColor={vars.ColorPrimaryActive}
        >
          <Text style={styles.text}>FlatList 滚动测试</Text>
        </TouchableHighlight>
        <TouchableHighlight
          style={styles.item}
          onPress={this.localOnClickItem.bind(this, "Demo2")}
        >
          <Text style={styles.text}>Img Blur 测试</Text>
        </TouchableHighlight>
        <TouchableHighlight
          style={styles.item}
          onPress={this.localOnClickItem.bind(this, "Demo3")}
        >
          <Text style={styles.text}>拖拽</Text>
        </TouchableHighlight>
        <TouchableHighlight
          style={styles.item}
          onPress={this.localOnClickItem.bind(this, "Demo3")}
        >
          <Text style={styles.text}>SnapCarousel</Text>
        </TouchableHighlight>

        <TouchableHighlight
          style={styles.item}
          onPress={this.localOnClickItem.bind(this, "Demo10")}
        >
          <Text style={styles.text}>水波效果</Text>
        </TouchableHighlight>
        <TouchableHighlight
          style={styles.item}
          onPress={this.localOnClickItem.bind(this, "test")}
        >
          <Text style={styles.text}>图片</Text>
        </TouchableHighlight>

        <TouchableHighlight
          style={styles.item}
          onPress={() => {
            const { navigation } = this.props;

            navigation.navigate("SearchDetail", { content: "result" });
          }}
        >
          <Text style={styles.text}>富文本</Text>
        </TouchableHighlight>

        <TouchableHighlight
          style={styles.item}
          onPress={() => {
            // 如果存在点击的链接  就需要点击跳转
            if (Platform.OS === "android") {
              RNReload.toWebViewActivity(
                "http://www.baidu.com/",
                "http://www.baidu.com/",
                " ",
                global.lang.main.close
              );
            } else {
              iOSModule.toWebView(
                "http://www.baidu.com/",
                " ",
                global.lang.main.close
              );
            }
          }}
        >
          <Text style={styles.text}>富文本</Text>
        </TouchableHighlight>
      </View>
    );
  }
}

export default index;
